import json
import os
import sys

pwd = os.path.dirname(os.path.realpath(__file__))
sys.path.append(pwd + "../")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hf_mall.settings")

import django

django.setup()
from goods.models import Goods, GoodsCategory
with open('./json/4/commodity.json', 'r', encoding='utf8')as fp:
    row_data = json.load(fp)

for good in row_data:
    good_instance = Goods()
    good_instance.good_sn = good['good_sn']
    good_instance.good_name = good['good_name']
    good_instance.good_brief = good['good_brief']
    good_instance.good_front_image = good['good_front_image']
    good_instance.shop_price = good['shop_price']
    good_instance.market_price = good['market_price']
    good_instance.stock_num = good['stock_num']
    good_instance.good_category = GoodsCategory.objects.filter(category_name=good['category_name'])[0]
    good_instance.save()